package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * 旅游游记推荐
 *
 * @author pengq
 */
@Setter
@Getter
public class TravelCommend extends BaseDomain {
    /**
     * 每周推荐
     */
    public static final int TYPE_WEEK = 1;
    /**
     * 没月推荐
     */
    public static final int TYPE_MONTH = 2;
    /**
     * 攻略推荐
     */
    public static final int TYPE_RAIDERS = 3;

    /**
     * 旅游游记
     */
    private Travel travel;
    /**
     * 标题
     */
    private String title;
    /**
     * 副标题
     */
    private String subTitle;
    /**
     * 封面
     */
    private String coverUrl;
    /**
     * 推荐时间安排
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT-8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date schedule;
    /**
     * 推荐类型
     */
    private Integer type;


    public String getTypeNaem() {
        String typeName = "";
        switch (type) {
            case TYPE_WEEK:
                typeName = "每周推荐";
                break;
            case TYPE_MONTH:
                typeName = "每月推荐";
                break;
            case TYPE_RAIDERS:
                typeName = "攻略推荐";
                break;
            default:
                break;
        }
        return typeName;
    }

    public String getJson() {
        HashMap<String, Object> map = new HashMap<>(10);
        map.put("id", id);
        if (travel != null) {
            map.put("travelId", travel.getId());
        }
        map.put("coverUrl", coverUrl);
        map.put("schedule", new SimpleDateFormat("yyyy-MM-dd").format(schedule));
        map.put("title", title);
        map.put("subTitle", subTitle);
        map.put("type", type);
        return JSON.toJSONString(map);
    }

}